import dom, { ajax, domg } from "../../init.js";
import { obj } from "../../index.js";
import { date } from "../../../util/date.js";
import { toarticle } from "../../navigation/eventhandle.js";

export default {
  async articlecommentsubmit() {
    const content = (domg("#commentcontent") as any).value.trim();
    const id = +(domg("#commentcontent") as any).getAttribute("index");
    if (!content) return alert("请输入内容");
    const createdTime = date("all");
    const result = await ajax.post("/articlecomment/add", {
      content,
      createdTime,
      id,
    });
    const data = JSON.parse(result as string) as {
      status: number;
      msg: string;
    };
    if (data.msg !== "ok") return alert("发布失败," + data.msg);
    const results = await ajax.get("/article/findpk", { id });
    const datas = JSON.parse(results as string);
    localStorage.setItem("article", JSON.stringify(datas.data));
    alert("发布成功");
    return (location.hash = "/index");
  },
};
